using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class BaoCaoDoanhThuThangDAO
    {
        public static bool Insert(BaoCaoDoanhThuThangDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaDoanhThuThang", bc.MaDoanhThuThang));
                sqlparam.Add(new SqlParameter("@NgayBaoCaoDoanhThuThang", bc.NgayBaoCaoDoanhThuThang));
                sqlparam.Add(new SqlParameter("@ThangDoanhThu", bc.ThangDoanhThu));
                sqlparam.Add(new SqlParameter("@TongDoanhThuThang", bc.TongDoanhThuThang));
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoDoanhThuThangInsert",sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static bool Delete(BaoCaoDoanhThuThangDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaDoanhThuThang", bc.MaDoanhThuThang));
               
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoDoanhThuThangDelete", sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static bool Update(BaoCaoDoanhThuThangDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaDoanhThuThang", bc.MaDoanhThuThang));
                sqlparam.Add(new SqlParameter("@NgayBaoCaoDoanhThuThang", bc.NgayBaoCaoDoanhThuThang));
                sqlparam.Add(new SqlParameter("@ThangDoanhThu", bc.ThangDoanhThu));
                sqlparam.Add(new SqlParameter("@TongDoanhThuThang", bc.TongDoanhThuThang));
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoDoanhThuThangUpdate", sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static List<BaoCaoDoanhThuThangDTO> Select()
        {
            List<BaoCaoDoanhThuThangDTO> lst = new List<BaoCaoDoanhThuThangDTO>();
            try
            {
               
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spBaoCaoDoanhThuThangSelect");
                foreach (DataRow dr in dt.Rows)
                {
                    BaoCaoDoanhThuThangDTO bc = new BaoCaoDoanhThuThangDTO();
                    bc.MaDoanhThuThang = int.Parse(dr["MaDoanhThuThang"].ToString());
                    bc.NgayBaoCaoDoanhThuThang = DateTime.Parse(dr["NgayBaoCaoDoanhThuThang"].ToString());
                    bc.ThangDoanhThu = DateTime.Parse(dr["ThangDoanhThu"].ToString());
                    bc.TongDoanhThuThang = float.Parse(dr["TongDoanhThuThang"].ToString());
                    lst.Add(bc);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return lst;
        }
        public static BaoCaoDoanhThuThangDTO SelectByID(int MaDoanhThuThang)
        {
            BaoCaoDoanhThuThangDTO bc = new BaoCaoDoanhThuThangDTO();
            try
            {
                List<SqlParameter> sqlParam = new List<SqlParameter>();
                sqlParam.Add(new SqlParameter("@MaDoanhThuThang", MaDoanhThuThang));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spBaoCaoDoanhThuThangSelectByID",sqlParam);
                DataRow dr = dt.Rows[0];
                bc.MaDoanhThuThang = int.Parse(dr["MaDoanhThuThang"].ToString());
                bc.NgayBaoCaoDoanhThuThang = DateTime.Parse(dr["NgayBaoCaoDoanhThuThang"].ToString());
                bc.ThangDoanhThu = DateTime.Parse(dr["ThangDoanhThu"].ToString());
                bc.TongDoanhThuThang = float.Parse(dr["TongDoanhThuThang"].ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return bc;
        }
    }
  }
